package zyz

import (
	"server/pkg/tools"
	"strconv"
	"time"
)

// 密钥
var key = "D5eCkH7V2n"

var quUrl = "https://wzl.dbw.cn/handinter/uc/quxian?cs=7"  // 区县
var jieUrl = "https://wzl.dbw.cn/handinter/uc/jiedao?qx=7" //街道
var sherl = "https://wzl.dbw.cn/handinter/uc/shequ?jd=7"   //社区

// GetQuList 获取区列表
func GetQuList() (map[string]any, error) {
	data := make(map[string]any)
	json, err := tools.PostJson(quUrl, header(""), data, "GET")

	return json, err
}

// GetJieList 获取街道列表
func GetJieList(id string) (map[string]any, error) {
	data := make(map[string]any)
	json, err := tools.PostJson(jieUrl, header(id), data, "GET")

	return json, err
}

// GetSheList 获取社区列表
func GetSheList(id string) (map[string]any, error) {
	data := make(map[string]any)
	json, err := tools.PostJson(sherl, header(id), data, "GET")

	return json, err
}

func header(id string) map[string]string {
	t := time.Now()
	head := make(map[string]string)
	head["h_timestamp"] = strconv.Itoa(int(t.Unix()))
	head["h_token"] = tools.GetMd5String(head["h_timestamp"] + key)
	if id != "" {
		head["id"] = id
	}
	return head
}
